<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <input id="inp" /><button id="btn">发送</button>
  <script src="./socket.io.min.js"></script>
  <script>
    const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJJRCI6NCwiaWF0IjoxNjMwMDU5NTY4LCJleHAiOjE2MzAwNzM5Njh9.yuEKsfCkXe_yfNl_ERuXN3xigHA_KkpdjHalZ5_LfTw';
    const socket = io('http://localhost:8081/robot')
    socket.emit('authenticate',{
      token
    })

    socket.on('connected',(data) => {
      if(data.code === 200){
        console.log(data);
      } else {
        socket.emit('close');
        alert(data.msg);
      }
    })

    socket.on('message',(data) => {
      console.log(data);
    })
    btn.onclick = function() {
      socket.emit('message',{
        val:inp.value,
        type:'talk'
      })
    }

  </script>
</body>
</html>